﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using Sunboxsoft.Common;

namespace Sunboxsoft.ASMS.Client.Domain.Service
{
    public class UpdateService
    {
        /// <summary>
        /// 更新车辆信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="automobile"></param>
        /// <returns></returns>
        public ServiceResult UpdateAutomobile(Guid id, WebRef.EAutomobile automobile)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.ServiceResult result = service.UpdateAutomobile(id, automobile);
                if (result.IsSuccess)
                {
                    return new ServiceResult();
                }
                return new ServiceResult(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new ServiceResult(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 更新预约单
        /// </summary>
        /// <param name="id"></param>
        /// <param name="bookingBill"></param>
        /// <param name="serviceArray"></param>
        /// <returns></returns>
        public ServiceResult UpdateBookingBill(Guid id, WebRef.EBookingBill bookingBill, WebRef.EBookingService[] serviceArray)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.ServiceResult result = service.UpdateBookingBill(id, bookingBill, serviceArray);
                if (result.IsSuccess)
                {
                    return new ServiceResult();
                }
                return new ServiceResult(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new ServiceResult(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 更新客户
        /// </summary>
        /// <param name="id"></param>
        /// <param name="customer"></param>
        /// <returns></returns>
        public ServiceResult UpdateCustomer(Guid id, WebRef.ECustomer customer)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.ServiceResult result = service.UpdateCustomer(id, customer);
                if (result.IsSuccess)
                {
                    return new ServiceResult();
                }
                return new ServiceResult(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new ServiceResult(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 更新出库单到完成状态
        /// </summary>
        /// <param name="bill"></param>
        /// <returns></returns>
        public ServiceResult UpdateWorkingBillToFinished(Guid maintenanceBillId, Guid maintenanceBillServiceItemId)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.ServiceResult result = service.UpdateWorkingBillToFinished(maintenanceBillId, maintenanceBillServiceItemId);
                if (result.IsSuccess)
                {
                    return new ServiceResult();
                }
                return new ServiceResult(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new ServiceResult(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 更新库存报警值
        /// </summary>
        /// <param name="stockWarning"></param>
        /// <returns></returns>
        public ServiceResult UpdateStockThresholdValue(WebRef.EStockThresholdValue thresholdValue)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.ServiceResult result = service.UpdateStockThresholdValue(thresholdValue);
                if (result.IsSuccess)
                {
                    return new ServiceResult();
                }
                return new ServiceResult(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new ServiceResult(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }
        
        /// <summary>
        /// 更新仓库
        /// </summary>
        /// <param name="id"></param>
        /// <param name="warehouse"></param>
        /// <returns></returns>
        public ServiceResult UpdateWarehouse(Guid id, WebRef.EWarehouse warehouse)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.ServiceResult result = service.UpdateWarehouse(id, warehouse);
                if (result.IsSuccess)
                {
                    return new ServiceResult();
                }
                return new ServiceResult(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new ServiceResult(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }
    }
}
